<template>
  <div>
       <el-form :model="datainfo" :rules="pwdForm" label-width="100px" ref="pwdFormRef">
      <el-form-item label="账号" prop="account">
        <el-input v-model="datainfo.account" minlength="6" maxlength="15"></el-input>
      </el-form-item>
      <el-form-item label="姓名" prop="name">
        <el-input v-model="datainfo.name"></el-input>
      </el-form-item>
      <el-form-item label="密码" prop="password">
        <el-input v-model="datainfo.password"></el-input>
      </el-form-item>
    </el-form>
     <div slot="footer" class="dialog-footer">
    <el-button size="small" @click="quxiao">取 消</el-button>
    <el-button size="small" type="primary" @click="queding">确 定</el-button>
  </div>
  </div>
</template>
<script>
import { addmember, editmember } from "@/api/limits";
export default {
  name:"newmember",
  props:{
    childata:{
      type: Object,
      require: true
    },
    isedite:{
      type: Boolean,
      required: true
    },
     },
data (){
  return{
    datainfo:{
      name:'',
      account:'',
      password:''
    },
    pwdForm:{
          password:[
        { required: true, message: '密码不能为空', trigger: 'blur' },
        { min: 6, max: 20, message: '密码为6-20位', trigger: 'blur' }
    ],
         account:[
        { required: true, message: '账号不能为空', trigger: 'blur' },
        { min: 6, max: 15, message: '账号为6-15位', trigger: 'blur' }
    ],
    }
  }
},
created(){
  this.loacdftig()
},
  
    methods:{
    loacdftig(){
       if(this.isedite==true){
         this.datainfo = this.childata
      // console.log('741',this.childata);
       } else{
        return
       }
     },
    // 取消
      quxiao(){
         if(this.isedite==true){
        console.log('编辑');
    }else{
         console.log('新增');
      }
        this.$emit('clone')
        this.$refs.pwdFormRef.resetFields()
      },
      // 确定
     async queding(){
      this.$refs.pwdFormRef.validate(async (valid) => {
        if(!valid) return
      if(this.isedite==true){
      const ress = await editmember(this.datainfo)
      console.log(ress);
      console.log('编辑');
    }else{ 
      const res = await addmember(this.datainfo)
      this.$message.success(res.msg)
      console.log('新增');
    }    
        this.$refs.pwdFormRef.resetFields()
        this.$emit('clone')
     })
      }
     
    }
}
</script>

<style scoped>
.dialog-footer{
 width: 45%;
 margin-left: 60%;
 margin-top: 20px;
}
.el-form{
  margin-right: 32px;
}
</style>